import type { FormRules } from "element-plus";

// 样例表单
export interface DemoForm {
    input:string
    confirmInput:string
    textarea:string
    number:number
    comboBox:string
    cascader:string
    radio:string
    checkBox:string
    switch:boolean
    date:string,
    dateTime:string,
}

// 样例表单（默认值）
export const defaultDemoForm:DemoForm = {
    input: "",
    confirmInput: "",
    textarea: "",
    number: 0,
    comboBox: "",
    cascader: "",
    radio: "0",
    checkBox: "",
    switch: false,
    date: "",
    dateTime: "",
}

// 样例表单（验证规则 自定义规则）
const customRule = (rule:any, value:any, callback:any) => {
    if (value === '') {
        callback(new Error('确认内容不可空！'))

        console.log(value)
    }
    else if (defaultDemoForm.input !== value) {
        callback(new Error('确认内容与内容不一致！'))

        console.log(defaultDemoForm.input)
    }
    else {
        callback()
    }
}

// 样例表单（验证规则）
export const demoFormRule:FormRules<DemoForm> = {
    input: [
        { required: true, message: '内容不可为空！', trigger: 'blur' },
        { min: 3, max: 5, message: '内容长度3~5的字符！', trigger: 'blur' },
    ],
    confirmInput: [
        { required: true, validator: customRule, trigger: 'blur' },
    ],
    textarea: [
        { required: true, message: '内容不可为空！', trigger: 'blur' }
    ],
    number: [
        { required: true, message: '数字不可为空！', trigger: 'blur' },
    ],
    comboBox: [
        { required: true, message: '选项不可为空！', trigger: 'change' },
    ],
    cascader: [
        { required: true, message: '选项不可为空！', trigger: 'change' },
    ],
    radio: [
        { required: true, message: '选项不可为空！', trigger: 'change' },
    ],
    checkBox: [
        { required: true, message: '选项不可为空！', trigger: 'change' },
    ],
    switch: [
        { required: true, message: '开关不可为空！', trigger: 'change' },
    ],
    date: [
        { type: 'date', required: true, message: '日期不可为空！', trigger: 'change' },
    ],
    dateTime: [
        { type: 'date', required: true, message: '时间不可为空！', trigger: 'change' },
    ]
}